package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.qdsg.ysg.doctor.R;
import com.rest.response.PrescriptionStatusBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * @Description: 开处方  处方状态审核页适配器
 * @Author: lzp
 * @CreateDate: 2022/5/17 10:31
 * @UpdateRemark: 更新说明
 */
public class PrescriptionStatusAdapter extends RecyclerView.Adapter<PrescriptionStatusAdapter.ViewHolder> {

    private Context mContext;
    private List<PrescriptionStatusBean> mList;

    public PrescriptionStatusAdapter(Context context, List<PrescriptionStatusBean> list) {
        this.mContext = context;
        this.mList = list;
    }


    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        ViewHolder myHolder;
        myHolder = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_prescription_status, parent, false));
        return myHolder;

    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NotNull ViewHolder holder, final int position) {

        holder.tvStepName.setText(mList.get(position).stepName);
        holder.tvError.setText(mList.get(position).errorMsg.replaceAll(";", "\n"));

        if (0 == mList.get(position).status) {
            holder.ivStatus.setImageResource(R.mipmap.icon_status_default);
            holder.tvStepName.setTextColor(ContextCompat.getColor(mContext, R.color.color_8b8888));
            holder.line.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_8b8888));
        } else if (1 == mList.get(position).status) {
            holder.ivStatus.setImageResource(R.mipmap.icon_status_complted);
            holder.tvStepName.setTextColor(ContextCompat.getColor(mContext, R.color.mainGreen));
            holder.line.setBackgroundColor(ContextCompat.getColor(mContext, R.color.mainGreen));
        } else if (2 == mList.get(position).status) {
            holder.ivStatus.setImageResource(R.mipmap.icon_status_attention);
            holder.tvStepName.setTextColor(ContextCompat.getColor(mContext, R.color.color_fe624f));
            holder.line.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_fe624f));
        }
        if (position == 2) {
            holder.line.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_status)
        ImageView ivStatus;
        @BindView(R.id.tv_step_name)
        TextView tvStepName;
        @BindView(R.id.tv_error)
        TextView tvError;
        @BindView(R.id.line)
        View line;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
